import 'package:flutter/material.dart';

/// 保活组件,[Widget]用此组件包裹则自动保活，也可以通过[keepAlive]设置不保活
class KqKeepAlive extends StatefulWidget {
  final Widget child;
  final bool keepAlive;

  const KqKeepAlive({super.key, required this.child, this.keepAlive = true});

  @override
  State<StatefulWidget> createState() => _KqKeepAliveState();
}

class _KqKeepAliveState extends State<KqKeepAlive>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return widget.child;
  }

  @override
  bool get wantKeepAlive => widget.keepAlive;
}
